package com.example.cici.datepick;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.DatePicker;
import android.widget.TextView;

import java.util.Calendar;

public class DatePick extends AppCompatActivity {

    private DatePicker datePickerStart;
    private DatePicker datePickerStop;
    private int startY;
    private int startM;
    private int stopY;
    private int stopM;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activitty);
        datePickerStart = (DatePicker) findViewById(R.id.date_pick_start);
        datePickerStop = (DatePicker) findViewById(R.id.date_pick_stop);

        datePickerStart.init(2015,8,28,new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(year, monthOfYear, dayOfMonth);
                startY = datePickerStart.getYear();
                startM = datePickerStart.getMonth()+1;
                TextView textView = (TextView) findViewById(R.id.tv_date_start);
                if (stopM<10){
                    textView.setText(startY+"0"+startM);
                }
                else {
                    textView.setText(startY+""+startM);
                }
                Log.e("startY",startY+""+startM);


            }
        });

        datePickerStop.init(2019, 8, 28, new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(year, monthOfYear, dayOfMonth);
                stopY = datePickerStop.getYear();
                stopM = datePickerStop.getMonth()+1;
                TextView textViewstop = (TextView) findViewById(R.id.tv_date_stop);
                if (stopM<10)
                {
                    textViewstop.setText(stopY+"0"+stopM);
                }
                else {
                    textViewstop.setText(stopY+""+stopM);
                }
                Log.e("startY",stopY+""+stopM);

            }
        });

    }
}
